import os
import os.path as osp
import re
import shutil

BASEDIR = osp.dirname(osp.abspath(__file__))

pattern = re.compile('_c(\d)')

# ImgDir = osp.abspath(r'/data1/DATA4REID/Market-1501-v15.09.15_train_all_styles/bounding_box_train_orig')
# TarDir = osp.abspath(r'/data1/DATA4REID/Market-1501_train_sep_camid')

# ImgDir = osp.abspath(r'/data1/DATA4REID/DukeMTMC-reID/DukeMTMC-reID/bounding_box_train')
# TarDir = osp.abspath(r'/data1/DATA4REID/DukeMTMC_train_sep_camid')

# ImgDir = osp.abspath(r'/data1/DATA4REID/DukeMTMC-reID/DukeMTMC-reID/query')
# TarDir = osp.abspath(r'/data1/DATA4REID/DukeMTMC_query_sep_camid')

ImgDir = osp.abspath(r'/data1/DATA4REID/Market-1501-v15.09.15_train_all_styles/query')
TarDir = osp.abspath(r'/data1/DATA4REID/Market-1501_query_sep_camid')

imgnames = [name for name in os.listdir(ImgDir) if name.split('.')[-1] in ['jpg', 'png', 'jpeg', 'tif', 'bmp']]
for imgname in imgnames:
    print(imgname, end=' ')
    camid = int(pattern.search(imgname).groups()[0])
    path_img = osp.join(ImgDir, imgname)
    dst_path = osp.join(TarDir, str(camid), imgname)
    if not osp.exists(osp.dirname(dst_path)):
        os.makedirs(osp.dirname(dst_path))
    shutil.copy(path_img, dst_path)
    print('copied')
